package com.spzx.product.controller;

import com.spzx.common.core.web.controller.BaseController;
import com.spzx.common.core.web.domain.AjaxResult;
import com.spzx.common.core.web.page.TableDataInfo;
import com.spzx.product.domain.Brand;
import com.spzx.product.domain.CategoryBrand;
import com.spzx.product.service.ICategoryBrandService;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 分类品牌 前端控制器
 * </p>
 *
 * @author atguigu
 * @since 2025-04-28
 */
@RestController
@RequestMapping("/categoryBrand")
public class CategoryBrandController extends BaseController {
@Autowired
   private ICategoryBrandService categoryBrandService;

@GetMapping("/list")
    public TableDataInfo list(){
    startPage();
    List<CategoryBrand> list =categoryBrandService.selectCategoryBrandList();
    return getDataTable(list);
}
@Operation
    @PostMapping
public AjaxResult saveCategoryBrand(@RequestBody CategoryBrand categoryBrand){
    categoryBrandService.saveCategoryBrand(categoryBrand);
    return AjaxResult.success();
}

@Operation(summary = "批量删除分类品牌关系")
    @DeleteMapping("/{ids}")
public AjaxResult delete(@PathVariable List<Long> ids){
    categoryBrandService.removeByIds(ids);
    return AjaxResult.success();
}

@Operation(summary = "根据三级分类ID查询品牌列表")
@GetMapping("/brandList/{categoryId}")
    public AjaxResult brandList(@PathVariable("categoryId") Long categoryId){
      List<Brand> list=categoryBrandService.brandList(categoryId);
      return  AjaxResult.success(list);
}
}
